<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  <style type="text/css">
    body, html{width: 100%;height: 100%;margin:0;font-family:"微软雅黑";font-size:14px;}
    #allmap {width:100%;height:100%;}
  </style>
  <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=C4kPwCxIpmGNFgZvaQg1EITOW2usiG5C"></script>
  <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
  <title>天网定位</title>
</head>
<body>

<div id="herder" style="width: 100%;height: 50px;font-size: 20px;background:#0080FF;color: white;text-align: center;padding-top: 15px;">
  天网定位
</div>
<div id="111" style="width: 100%;height: 50px;font-size: 20px;background:#0080FF;color: white;text-align: center;padding-top: 12px;">
所在位置:
</div>
<div id="text" style="width: 100%;height: 50px;font-size: 20px;background:#0080FF;color: white;text-align: center;padding-top: 12px;">

</div>
  <div id="allmap"></div>
<div id="footer">
</div>
<script type="text/javascript">
	//自动定位
    var lng,lat;
    var map = new BMap.Map("allmap");
    var point = new BMap.Point(104.098225,30.56028);
    map.centerAndZoom(point,12);
    var geolocation = new BMap.Geolocation();

    geolocation.getCurrentPosition(function(r){
        if(this.getStatus() == BMAP_STATUS_SUCCESS){
            var mk = new BMap.Marker(r.point);
            map.addOverlay(mk);
            map.panTo(r.point);
            lng=r.point.lng;
            lat=r.point.lat;
            point = new BMap.Point(lng,lat);
            console.log('所在位置：'+r.point.lng+','+r.point.lat);
         aaa(lng,lat);
        }
        else {
            console.log('failed'+this.getStatus());
        }


    });

    //根据经纬度转换成地址
    function aaa(lng,lat){
        var map1 = new BMap.Map("allmap");
        var point = new BMap.Point(lng,lat);

        map1.centerAndZoom(point,12);
        var geoc = new BMap.Geocoder();
        geoc.getLocation(point,function(rs){
            var addComp = rs.addressComponents;
            // alert(addComp.province + "," + addComp.city + "," + addComp.district + "," + addComp.street + "," + addComp.streetNumber);
            //赋值到注册页的所在区域
            // $(".locationCoun").html(addComp.district);
             console.log(addComp);
            $('#text').html(addComp.province + ","+addComp.city +"," + addComp.district + "," + addComp.street);

        });
    }
</script>

</body>
</html>